<?php

declare(strict_types=1);

namespace Tempest\Vite;

final class ViteConfig
{
    /**
     * @param PrefetchConfig $prefetching Strategy for prefetching assets at runtime.
     * @param null|string $nonce The Content Security Policy nonce to apply to all generated tags.
     * @param string|false $integrityKey The key to check for integrity hashes within the manifest. Set to `false` to disable.
     * @param bool $useManifestDuringTesting Whether to use the manifest during tests. `false` by default.
     * @param string $buildDirectory Name of the directory in which assets will be created by Vite. Relative to the `public` directory.
     * @param string $bridgeFileName Name of the bridge file that the development server creates for Tempest to read. Relative to the `public` directory.
     * @param string $manifest Name of the build manifest file generated by Vite for Tempest to read.
     * @param string[] $entrypoints Paths to the entrypoints, relative to the root of the project.
     */
    public function __construct(
        public PrefetchConfig $prefetching = new PrefetchConfig(),
        public ?string $nonce = null,
        public string|false $integrityKey = 'integrity',
        public bool $useManifestDuringTesting = false,
        public string $buildDirectory = 'build',
        public string $bridgeFileName = 'vite-tempest',
        public string $manifest = 'manifest.json',
        public array $entrypoints = [],
        public array $discoverableExtensions = ['ts', 'tsx', 'js', 'jsx', 'css'],
    ) {}

    public function addEntrypoint(string $path): void
    {
        $this->entrypoints[] = $path;
    }
}
